<?php
namespace app\admin\controller;

class Culture extends BaseAdmin
{
    public function index()
    {
        $re=db("about")->where("id=4")->find();
        $this->assign("re",$re);
        return view('index');
    }
    public function saves()
    {
        $re=db("about")->where("id=4")->find();
        $data=\input('post.');
    
       
        $res=db("about")->where("id=4")->update($data);
        if($res){
            $this->success("修改成功");
        }else{
            $this->error("修改失败");
        }
    }
    public function lister()
    {
        $list=db("salon")->order("sort asc")->paginate(20);
        $this->assign("list",$list);
    
        $page=$list->render();
        $this->assign("page",$page);
    
        return \view('lister');
    }
    public function add()
    {
        return \view("add");
    }
    public function saveh()
    {
        $data=\input('post.');
        if(!\is_string(\input('image'))){
            $data['image']=\uploads("image");
        }
        if(\input('status')){
            $data['status']=1;
        }
        $data['time']=\time();
        $re=db("salon")->insert($data);
        if($re){
            $this->success("添加成功");
        }else{
            $this->error("添加失败");
        }
    }
    public function sort(){
        $data=input('post.');
        $news=db('salon');
        foreach ($data as $id => $sort){
            $news->where(array('id' => $id ))->setField('sort' , $sort);
        }
        $this->redirect('lister');
    }
    public function delete_all(){
        $id=input('id');
        $arr=explode(",", $id);
        foreach ($arr as $v){
            $re=db('salon')->where("id=$v")->find();
            if($re){
                 
                $del=db('salon')->where("id=$v")->delete();
    
            }else{
                return false;
            }
        }
        $this->redirect('lister');
    }
    public function change(){
        $id=\input('id');
        $re=db("salon")->where("id=$id")->find();
        if($re){
            if($re['status'] == 1){
                $res=db('salon')->where("id=$id")->setField("status",0);
                return $res;
            }elseif($re['status'] == 0){
                $res=db('salon')->where("id=$id")->setField("status",1);
                return $res;
            }
        }else{
            return false;
        }
        if($res){
            echo '1';
        }else{
            echo '0';
        }
    }
    public function delete(){
        $id=input('id');
        $re=db('salon')->where("id=$id")->find();
        if($re){
            $del=db('salon')->where("id=$id")->delete();
        }
    
        $this->redirect('lister');
    }
    public function modifys()
    {
        $id=\input('id');
        $re=db("salon")->where("id=$id")->find();
        $this->assign("re",$re);
        return \view('modifys');
    }
    public function usave()
    {
        $id=\input('id');
        $re=db("salon")->where("id=$id")->find();
    
        if($re){
            $data=\input('post.');
            if(!\is_string(\input('image'))){
                $data['image']=\uploads("image");
            }else{
                $data['image']=$re["image"];
            }
            if(\input('status')){
                $data['status']=1;
            }else{
                $data['status']=$re['status'];
            }
            $res=db("salon")->where("id=$id")->update($data);
            if($res){
                $this->success("修改成功",\url('lister'));
            }else{
                $this->error("修改失败",\url('lister'));
            }
        }else{
            $this->error("非法操作",\url('lister'));
        }
    
    }
    
}